/* USER CODE BEGIN Header */
/**
 ******************************************************************************
 * @file           : main.c
 * @brief          : Main program body
 ******************************************************************************
 * @attention
 *
 * Copyright (c) 2024 STMicroelectronics.
 * All rights reserved.
 *
 * This software is licensed under terms that can be found in the LICENSE file
 * in the root directory of this software component.
 * If no LICENSE file comes with this software, it is provided AS-IS.
 *
 ******************************************************************************
 */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include <stdio.h>
#include <stdint.h>
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
uint16_t Tim1Count = 0, FG1DispFreq = 0, FG2DispFreq = 0;
uint16_t FG1Count = 0, FG2Count = 0, FG1TimCount = 0, FG2TimCount = 0, FG1Freq = 0, FG2Freq = 0;
uint8_t Uart1Data[6] = {8, 0, 0, 0, 0, 0};
uint8_t Uart1Disp[2] = {0X18, 0X1C};
uint8_t Uart2Data[8] = {8, 0, 0, 0, 0, 0, 0X18, 0X18};

uint8_t FG1FreqIndex = 0, FG2FreqIndex = 0;
uint16_t FG1FreqArray[3] = {100, 100, 100};
uint16_t FG2FreqArray[3] = {100, 100, 100};
/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/
TIM_HandleTypeDef htim14;

UART_HandleTypeDef huart1;
UART_HandleTypeDef huart2;
DMA_HandleTypeDef hdma_usart1_tx;
DMA_HandleTypeDef hdma_usart1_rx;
DMA_HandleTypeDef hdma_usart2_tx;
DMA_HandleTypeDef hdma_usart2_rx;

/* USER CODE BEGIN PV */

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_DMA_Init(void);
static void MX_USART1_UART_Init(void);
static void MX_USART2_UART_Init(void);
static void MX_TIM14_Init(void);
/* USER CODE BEGIN PFP */
void tm1652_show(uint16_t FG1FreqDataShow, uint16_t FG2FreqDataShow);
/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */

void my_delay_ms(uint16_t ms)
{
		uint16_t i = 0;
		while(ms--)
		{
			i = 4050;
			while(i--);
		};
}
/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_USART1_UART_Init();
  MX_USART2_UART_Init();
  MX_TIM14_Init();
  /* USER CODE BEGIN 2 */
  //  HAL_TIM_IC_Start_IT(&htim1, TIM_CHANNEL_1);
  //  HAL_TIM_IC_Start_IT(&htim3, TIM_CHANNEL_1);
  HAL_TIM_Base_Start_IT(&htim14);

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    HAL_Delay(500);
		/*
    FG1DispFreq = 0;
    FG2DispFreq = 0;
    for (int i = 0; i < 3; i++)
    {
      FG1DispFreq += FG1FreqArray[i];
      FG2DispFreq += FG2FreqArray[i];
    }
    FG1DispFreq = FG1DispFreq / 3;
    FG2DispFreq = FG2DispFreq / 3;*/
		if(HAL_GPIO_ReadPin(PowerState1_GPIO_Port,PowerState1_Pin))
			HAL_GPIO_WritePin(LED1_GPIO_Port,LED1_Pin,GPIO_PIN_RESET);
		else
			HAL_GPIO_WritePin(LED1_GPIO_Port,LED1_Pin,GPIO_PIN_SET);
		
		if(HAL_GPIO_ReadPin(PowerState2_GPIO_Port,PowerState2_Pin))
			HAL_GPIO_WritePin(LED2_GPIO_Port,LED2_Pin,GPIO_PIN_RESET);
		else
			HAL_GPIO_WritePin(LED2_GPIO_Port,LED2_Pin,GPIO_PIN_SET);
		
    tm1652_show(FG1DispFreq, FG2DispFreq);

    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  /** Configure the main internal regulator output voltage
  */
  HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);

  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV1;
  RCC_OscInitStruct.PLL.PLLN = 8;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

  /** Initializes the CPU, AHB and APB buses clocks
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  {
    Error_Handler();
  }
}

/**
  * @brief TIM14 Initialization Function
  * @param None
  * @retval None
  */
static void MX_TIM14_Init(void)
{

  /* USER CODE BEGIN TIM14_Init 0 */

  /* USER CODE END TIM14_Init 0 */

  /* USER CODE BEGIN TIM14_Init 1 */

  /* USER CODE END TIM14_Init 1 */
  htim14.Instance = TIM14;
  htim14.Init.Prescaler = 64-1;
  htim14.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim14.Init.Period = 1000-1;
  htim14.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  htim14.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  if (HAL_TIM_Base_Init(&htim14) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN TIM14_Init 2 */

  /* USER CODE END TIM14_Init 2 */

}

/**
  * @brief USART1 Initialization Function
  * @param None
  * @retval None
  */
static void MX_USART1_UART_Init(void)
{

  /* USER CODE BEGIN USART1_Init 0 */

  /* USER CODE END USART1_Init 0 */

  /* USER CODE BEGIN USART1_Init 1 */

  /* USER CODE END USART1_Init 1 */
  huart1.Instance = USART1;
  huart1.Init.BaudRate = 19200;
  huart1.Init.WordLength = UART_WORDLENGTH_9B;
  huart1.Init.StopBits = UART_STOPBITS_1;
  huart1.Init.Parity = UART_PARITY_ODD;
  huart1.Init.Mode = UART_MODE_TX_RX;
  huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart1.Init.OverSampling = UART_OVERSAMPLING_16;
  huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
  huart1.Init.ClockPrescaler = UART_PRESCALER_DIV1;
  huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  if (HAL_UART_Init(&huart1) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_UARTEx_SetTxFifoThreshold(&huart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_UARTEx_SetRxFifoThreshold(&huart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_UARTEx_DisableFifoMode(&huart1) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN USART1_Init 2 */

  /* USER CODE END USART1_Init 2 */

}

/**
  * @brief USART2 Initialization Function
  * @param None
  * @retval None
  */
static void MX_USART2_UART_Init(void)
{

  /* USER CODE BEGIN USART2_Init 0 */

  /* USER CODE END USART2_Init 0 */

  /* USER CODE BEGIN USART2_Init 1 */

  /* USER CODE END USART2_Init 1 */
  huart2.Instance = USART2;
  huart2.Init.BaudRate = 19200;
  huart2.Init.WordLength = UART_WORDLENGTH_9B;
  huart2.Init.StopBits = UART_STOPBITS_1;
  huart2.Init.Parity = UART_PARITY_ODD;
  huart2.Init.Mode = UART_MODE_TX_RX;
  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
  huart2.Init.ClockPrescaler = UART_PRESCALER_DIV1;
  huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  if (HAL_UART_Init(&huart2) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN USART2_Init 2 */

  /* USER CODE END USART2_Init 2 */

}

/**
  * Enable DMA controller clock
  */
static void MX_DMA_Init(void)
{

  /* DMA controller clock enable */
  __HAL_RCC_DMA1_CLK_ENABLE();

  /* DMA interrupt init */
  /* DMA1_Channel1_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn);
  /* DMA1_Channel2_3_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(DMA1_Channel2_3_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(DMA1_Channel2_3_IRQn);
  /* DMA1_Ch4_5_DMAMUX1_OVR_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(DMA1_Ch4_5_DMAMUX1_OVR_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(DMA1_Ch4_5_DMAMUX1_OVR_IRQn);

}

/**
  * @brief GPIO Initialization Function
  * @param None
  * @retval None
  */
static void MX_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
/* USER CODE BEGIN MX_GPIO_Init_1 */
/* USER CODE END MX_GPIO_Init_1 */

  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOB_CLK_ENABLE();
  __HAL_RCC_GPIOC_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE();

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOB, LED2_Pin|LED1_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pins : LED2_Pin LED1_Pin */
  GPIO_InitStruct.Pin = LED2_Pin|LED1_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  /*Configure GPIO pin : LED3_Pin */
  GPIO_InitStruct.Pin = LED3_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(LED3_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pin : PowerState2_Pin */
  GPIO_InitStruct.Pin = PowerState2_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(PowerState2_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pins : FG1_Pin FG2_Pin */
  GPIO_InitStruct.Pin = FG1_Pin|FG2_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /*Configure GPIO pin : PowerState1_Pin */
  GPIO_InitStruct.Pin = PowerState1_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(PowerState1_GPIO_Port, &GPIO_InitStruct);

  /* EXTI interrupt init*/
  HAL_NVIC_SetPriority(EXTI4_15_IRQn, 2, 0);
  HAL_NVIC_EnableIRQ(EXTI4_15_IRQn);

/* USER CODE BEGIN MX_GPIO_Init_2 */
/* USER CODE END MX_GPIO_Init_2 */
}

/* USER CODE BEGIN 4 */

/*HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{

  if (htim->Instance == htim1.Instance)
  {
    if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1)
    {
      FG1Count = HAL_TIM_ReadCapturedValue(&htim1, TIM_CHANNEL_1);
      if (FG1Count != 0)
        FG1Freq = 60000 / FG1Count;
    }
  }

  if (htim->Instance == htim3.Instance)
  {
    if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1)
    {
      FG2Count = HAL_TIM_ReadCapturedValue(&htim1, TIM_CHANNEL_1);
      if (FG2Count != 0)
        FG2Freq = 60000 / FG2Count;
    }
  }
}*/

// 数码管显示字符对应显示数据转
uint8_t tm1652_transform(uint8_t showChar)
{
  uint8_t data = 0xff;
  switch (showChar)
  {
  case 0://case '0':
    data = 0x3F;
    break; // 0
  case 1://case '1':
    data = 0x06;
    break; // 1
  case 2://case '2':
    data = 0x5B;
    break; // 2
  case 3://case '3':
    data = 0x4F;
    break; // 3
  case 4://case '4':
    data = 0x66;
    break; // 4
  case 5://case '5':
    data = 0x6D;
    break; // 5
  case 6://case '6':
    data = 0x7D;
    break; // 6
  case 7://case '7':
    data = 0x07;
    break; // 7
  case 8://case '8':
    data = 0x7F;
    break; // 8
  case 9://case '9':
    data = 0x6F;
    break; // 9
  case 'A':
    data = 0x77;
    break; // A
  case 'B':
    data = 0x7C;
    break; // B
  case 'C':
    data = 0x39;
    break; // C
  case 'D':
    data = 0x5E;
    break; // D
  case 'E':
    data = 0x79;
    break; // E
  case 'F':
    data = 0x71;
    break; // F
  }
  return data;
}
void tm1652_show(uint16_t FG1FreqDataShow, uint16_t FG2FreqDataShow)
{
  static uint16_t FG1FreqData, FG2FreqData, DemoData = 0;
  FG1FreqData = FG1FreqDataShow;
  FG2FreqData = FG2FreqDataShow;
	
	DemoData++;
	if(DemoData>9999)
		DemoData=0;
	
//	FG1FreqData = DemoData;

  if (FG1FreqData > 9999)
    FG1FreqData = 9999;
  if (FG2FreqData > 9999)
    FG2FreqData = 9999;
/*
  Uart1Data[4] = tm1652_transform(FG1FreqData % 10);
  Uart1Data[3] = tm1652_transform((FG1FreqData % 100) / 10);
  Uart1Data[2] = tm1652_transform((FG1FreqData % 1000) / 100);
  Uart1Data[1] = tm1652_transform(FG1FreqData / 1000);*/
	
//	Uart1Data[1]=0X3F;
//	Uart1Data[2]=0X06;
//	Uart1Data[3]=0X5B;
//	Uart1Data[4]=0X4F;
//	Uart1Data[5]=0XFF;
	
	Uart1Data[1] = tm1652_transform(FG2FreqData/1000);
	Uart1Data[2] = tm1652_transform((FG2FreqData % 1000) / 100);
	Uart1Data[3] = tm1652_transform((FG2FreqData % 100) / 10);
	Uart1Data[4] = tm1652_transform(FG2FreqData % 10);

  
	

  Uart2Data[4] = tm1652_transform(FG1FreqData % 10);
  Uart2Data[3] = tm1652_transform((FG1FreqData % 100) / 10);
  Uart2Data[2] = tm1652_transform((FG1FreqData % 1000) / 100);
  Uart2Data[1] = tm1652_transform(FG1FreqData / 1000);
	
	
	HAL_UART_Transmit_DMA(&huart1, Uart1Data, 6);
	//HAL_UART_Transmit_IT(&huart2,Uart1Data,6);
	HAL_Delay(10);
	//HAL_UART_Transmit_IT(&huart2,Uart1Disp,2);
	HAL_UART_Transmit_DMA(&huart1, Uart1Disp, 2);
	HAL_Delay(5);

  HAL_UART_Transmit_DMA(&huart2, Uart2Data, 6);
	HAL_Delay(10);
	HAL_UART_Transmit_DMA(&huart2, Uart1Disp, 2);
	HAL_Delay(5);
	//HAL_UART_Transmit_DMA(&huart2, Uart2Data, 8);
}

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
  if (htim->Instance == htim14.Instance)
  {
    Tim1Count++;
    if (Tim1Count >= 500)
    {
      Tim1Count = 0;
      HAL_GPIO_TogglePin(LED3_GPIO_Port, LED3_Pin);
    }

    FG1TimCount++;
    FG2TimCount++;

    if ((FG1TimCount > 2000) && (FG1Count < 2))
    {
      /*FG1FreqIndex++;
      if (FG1FreqIndex > 2)
        FG1FreqIndex = 0;
      FG1FreqArray[0] = FG1FreqArray[1] = FG1FreqArray[2] = FG1Count * 30;*/
			FG1DispFreq = 0;
      FG1Count = 0;
      FG1TimCount = 0;
    }

    if ((FG2TimCount > 2000) && (FG2Count < 2))
    {
      /*FG2FreqIndex++;
      if (FG2FreqIndex > 2)
        FG2FreqIndex = 0;
      FG2FreqArray[0] = FG2FreqArray[1] = FG2FreqArray[2] = FG2Count * 30;*/
			FG2DispFreq = 0;
      FG2Count = 0;
      FG2TimCount = 0;
    }
  }
}

void HAL_GPIO_EXTI_Rising_Callback(uint16_t GPIO_Pin)
{
  if (GPIO_Pin == FG1_Pin)
  {
    HAL_Delay(2);
    if (HAL_GPIO_ReadPin(FG1_GPIO_Port, FG1_Pin) == GPIO_PIN_SET)
    {
      FG1Count++;
      if ((FG1Count >= 2) && (FG1TimCount != 0))
      {
        FG1FreqIndex++;
        if (FG1FreqIndex > 2)
          FG1FreqIndex = 0;
        FG1FreqArray[FG1FreqIndex] = 120000 / FG1TimCount;
        FG1TimCount = 0;
        FG1Count = 0;
      }
    }
  }

  if (GPIO_Pin == FG2_Pin)
  {
    HAL_Delay(2);
    if (HAL_GPIO_ReadPin(FG2_GPIO_Port, FG2_Pin) == GPIO_PIN_SET)
    {
      FG2Count++;
      if ((FG2Count >= 2) && (FG2TimCount != 0))
      {
        FG2FreqIndex++;
        if (FG2FreqIndex > 2)
          FG2FreqIndex = 0;
        FG2FreqArray[FG2FreqIndex] = 120000 / FG2TimCount;
        FG2TimCount = 0;
        FG2Count = 0;
      }
    }
  }
}

void HAL_GPIO_EXTI_Falling_Callback(uint16_t GPIO_Pin)
{
	if (GPIO_Pin == FG1_Pin)
  {
    my_delay_ms(5);
    if (HAL_GPIO_ReadPin(FG1_GPIO_Port, FG1_Pin) == GPIO_PIN_RESET)
    {
      FG1Count++;
      if ((FG1Count >= 2) && (FG1TimCount != 0))
      {
        /*FG1FreqIndex++;
        if (FG1FreqIndex > 2)
          FG1FreqIndex = 0;
        FG1FreqArray[FG1FreqIndex] = 120000 / FG1TimCount;*/
				FG1DispFreq = 120000 / FG1TimCount;
				
        FG1TimCount = 0;
        FG1Count = 0;
      }
    }
  }

  if (GPIO_Pin == FG2_Pin)
  {
    my_delay_ms(5);
    if (HAL_GPIO_ReadPin(FG2_GPIO_Port, FG2_Pin) == GPIO_PIN_RESET)
    {
      FG2Count++;
      if ((FG2Count >= 2) && (FG2TimCount != 0))
      {
        /*FG2FreqIndex++;
        if (FG2FreqIndex > 2)
          FG2FreqIndex = 0;
        FG2FreqArray[FG2FreqIndex] = 120000 / FG2TimCount;*/
				FG2DispFreq = 120000 / FG2TimCount;
				
        FG2TimCount = 0;
        FG2Count = 0;
      }
    }
  }
}
/* USER CODE END 4 */

/**
  * @brief  This function is executed in case of error occurrence.
  * @retval None
  */
void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */
  __disable_irq();
  while (1)
  {
  }
  /* USER CODE END Error_Handler_Debug */
}

#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
